package com.controller;

import com.pojo.Complaintadvice;
import com.pojo.Result;
import com.service.ComplaintadviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//跨域
@CrossOrigin
@RestController
@RequestMapping("/complaintAdvice")
public class ComplaintadviceController {
    //注入complaintadviceService
    @Autowired
    private ComplaintadviceService complaintadviceService;
    @GetMapping("/findByUid/{uid}")
    public Result findByUid(@PathVariable Integer uid){
        List list = complaintadviceService.findByUid(uid);
        Result result = new Result();

        if (list != null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(list);
        }else {
            result.setCode(500);
            result.setMsg("查询失败");
            //result.setData(list);
        }

        return result;
    }

    //添加
    @PostMapping
    public Result add(@RequestBody Complaintadvice complaintadvice){
        boolean flag = complaintadviceService.add(complaintadvice);
        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("添加成功");
        }else{
            result.setCode(500);
            result.setMsg("添加失败");
        }

        return result;
    }

    //删除
    @PostMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        boolean flag = complaintadviceService.delete(id);
        Result result = new Result();
        if(flag){
            result.setCode(200);
            result.setMsg("删除成功");
        }else{
            result.setCode(500);
            result.setMsg("删除失败");
        }

        return result;
    }
}
